import Vue from "vue";
import Vuex from "vuex";
import axios from "axios";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    list: [],
  },
  mutations: {
    setState(state, payload) {
      state[payload.key] = payload.value;
    },
  },
  actions: {
    // 获取数据
    async getList({ commit }) {
      let res = await axios.get("/api/list/get");
      console.log(res.data.data);
      commit("setState", { key: "list", value: res.data.data });
    },
    // 删除数据
    async del({ commit }, payload) {
      let { id } = payload;
      let res = await axios.delete("/api/list/del", { params: { id } });
      console.log(commit, res);
    },
    // 添加数据
    async add({ commit }, payload) {
      let res = await axios.put("/api/list/add", payload);
      console.log(commit, res);
    },
    // 编辑数据
    async edit({ commit }, payload) {
      let res = await axios.put("/api/list/edit", payload);
      console.log(commit, res);
    },

    // 运营获取数据
    async yunList({ commit }) {
      let res = await axios.get("/api/list/yun");
      console.log(res.data.data);
      commit("setState", { key: "list", value: res.data.data });
    },
    // 运营删除数据
    async yundel({ commit }, payload) {
      let { id } = payload;
      let res = await axios.delete("/api/list/yundel", { params: { id } });
      console.log(commit, res);
    },
    // 运营添加数据
    async yunadd({ commit }, payload) {
      let res = await axios.put("/api/list/yunadd", payload);
      console.log(commit, res);
    },
    // 运营编辑数据
    async yunedit({ commit }, payload) {
      let res = await axios.put("/api/list/yunedit", payload);
      console.log(commit, res);
    },

    // 佣金获取数据
    async setList({ commit }) {
      let res = await axios.get("/api/list/set");
      console.log(res.data.data);
      commit("setState", { key: "list", value: res.data.data });
    },

    // 会员获取数据
    async huiList({ commit }) {
      let res = await axios.get("/api/list/hui");
      console.log(res.data.data);
      commit("setState", { key: "list", value: res.data.data });
    },
    // 会员搜索数据
    async huisearch({ commit }, payload) {
      let { input } = payload;
      let res = await axios.get("/api/list/huisearch", payload);
      console.log(commit, res, input);
      commit("setState", { key: "list", value: res.data.data });
    },
  },
  modules: {},
});
